package com.ruoyi.web.controller.OrderGoods;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.OrderGoods.domain.OrderGoods;
import com.ruoyi.OrderGoods.service.IOrderGoodsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 订单商品中间 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-08
 */
@Controller
@RequestMapping("/OrderGoods/orderGoods")
public class OrderGoodsController extends BaseController
{
    private String prefix = "OrderGoods/orderGoods";
	
	@Autowired
	private IOrderGoodsService orderGoodsService;
	
	@RequiresPermissions("OrderGoods:orderGoods:view")
	@GetMapping()
	public String orderGoods()
	{
	    return prefix + "/orderGoods";
	}
	
	/**
	 * 查询订单商品中间列表
	 */
	@RequiresPermissions("OrderGoods:orderGoods:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(OrderGoods orderGoods)
	{
		startPage();
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出订单商品中间列表
	 */
	@RequiresPermissions("OrderGoods:orderGoods:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderGoods orderGoods)
    {
    	List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        ExcelUtil<OrderGoods> util = new ExcelUtil<OrderGoods>(OrderGoods.class);
        return util.exportExcel(list, "orderGoods");
    }
	
	/**
	 * 新增订单商品中间
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单商品中间
	 */
	@RequiresPermissions("OrderGoods:orderGoods:add")
	@Log(title = "订单商品中间", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(OrderGoods orderGoods)
	{		
		return toAjax(orderGoodsService.insertOrderGoods(orderGoods));
	}

	/**
	 * 修改订单商品中间
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		OrderGoods orderGoods = orderGoodsService.selectOrderGoodsById(id);
		mmap.put("orderGoods", orderGoods);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单商品中间
	 */
	@RequiresPermissions("OrderGoods:orderGoods:edit")
	@Log(title = "订单商品中间", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(OrderGoods orderGoods)
	{		
		return toAjax(orderGoodsService.updateOrderGoods(orderGoods));
	}
	
	/**
	 * 删除订单商品中间
	 */
	@RequiresPermissions("OrderGoods:orderGoods:remove")
	@Log(title = "订单商品中间", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(orderGoodsService.deleteOrderGoodsByIds(ids));
	}
	
}
